import 'package:im_app/im/socket/SignalWebSocket.dart';

import '../socket/dto/business/Login.dart';

class SignalSession {

  String userId;
  final Map<String, Object> _sessionDataMap = {};
  SignalWebSocket signalWebSocket;

  SignalSession(this.userId, this.signalWebSocket);

  void loginSuccess(String userId, int authCode, String token, String authToken, String tenantCode, DateTime
    serverDate) {
    putData('token', token);
    putData('authCode', authCode);
    putData('authToken', authToken);
    putData('tenantCode', tenantCode);
    putData('serverDate', serverDate);
  }

  void loginSuccess2(LoginResp loginResp) {
    putData('token', loginResp.token);
    putData('authCode', loginResp.authCode);
    putData('authToken', loginResp.authToken);
    putData('tenantCode', loginResp.tenantCode);
    putData('serverDate', loginResp.serverDateTime);
  }

  Object? getData(String key) {
    return _sessionDataMap[key];
  }

  void putData(String key, Object data) {
    _sessionDataMap[key] = data;
  }

  bool has(String key) {
    return _sessionDataMap.containsKey(key);
  }

  Object? delete(String key) {
    if (has(key)) {
      return _sessionDataMap.remove(key);
    }
    return null;
  }

  void close() {
    _sessionDataMap.clear();
  }
}